requirejs.config({
    baseUrl:"src/js/",
    paths:{
        "jquery":["lib/jquery-3.3.1"],
        "jquery.validate":["lib/jquery.validate"],
        "additional-methods":["lib/additional-methods"],
        "yzm":["lib/jquery.idcode"],
            shim:{
            "yzm":{
                deps:["jquery"]
            }

            }
    }
});
require(["jquery","jquery.validate", "additional-methods", "yzm"],function ($) {
    console.log($);
//验证码
    $(function () {
        $.idcode.setCode();
        $("#Txtidcode").on("blur", function () {
            let flag = $.idcode.validateCode();//返回值
            console.log(flag);
            if (flag) {
                //alert("正确")
            } else {
                confirm("验证码错误请重新输入")
            }

        });


    });

    $(function () {
        $.validator.addMethod("checkUname", function (val, ele, param) {
            var reg =/^[a-z]+\w+$/i;
            return reg.test(val);
        })

        $("#myform").validate({
            //规则
            rules: {
                uname: {
                    required: true,
                    checkUname: true,
                    remote:{
                        url:"http://127.0.0.1:80/diwu/sever/checkUser.php",
                        type:"get",
                        data:{
                            "uname":function () {
                                return $("input[name=uname]").val();
                            }
                        }
                    }


                },

                upwd: {
                    required: true,
                    rangelength: [6, 11]
                },
                upwd2: {
                    required: true,
                    equalTo: "#pwd"
                }
            },
            //提示信息
            messages: {
                uname: {
                    required: "用户名必填",
                    checkUname: "用户名必须以字母开头",
                    remote:"该用户名已注册"
                },

                upwd: {
                    required: "密码必填",
                    rangelength: "密码长度{0}-{1}位"

                },
                upwd2: {
                    equalTo: "两次密码不一致",
                    required: "请确认密码"
                }
            },
            //提交
            submitHandler: function () {
                $.ajax({
                    url:"http://127.0.0.1:80/diwu/sever/register1.php",
                    type:"post",
                    dataType:"json",
                    data:{
                        uname:$("input[name=uname]").val(),
                        upwd:$("input[name=upwd]").val(),

                    }

                }).then(function (result) {


                    if (result.status==1){
                        confirm("注册成功,是否立即登录")?window.location="login.html":"";
                        //alert(result.msg);

                    }//else{
                    //     alert(result.msg);
                    //
                    // }
                })

                return false;
            }
        });
        var closeA = document.querySelector(".popup_main a");
        closeA.onclick = function () {
            this.parentNode.parentNode.style.display = "none";
        };
        $(".footer").load('./footer.html',function () {
            //console.log("底部加载完成后执行");
        })

    });


   })
